home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / ssi.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  8.3 KB  |  360 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > SSI script
  17. |   > Script written by Matt Mecham
  18. |   > Date started: 29th April 2002
  19. |
  20. +--------------------------------------------------------------------------
  21. */
  22.  
  23. /* USAGE:
  24.    ------
  25.    
  26.    Simply call this script via PHP includes, or SSI .shtml tags to generate content
  27.    on the fly, streamed into your own webpage.
  28.    
  29.    To show the last 10 topics and posts in the news forums...
  30.    
  31.    include("http://domain.com/forums/ssi.php?a=news&show=10");
  32.    
  33.    You can adjust the "show" attribute to display a different amount of topics.
  34.    
  35.    To show the board statistics
  36.    
  37.    include("http://domain.com/forums/ssi.php?a=stats");
  38.    
  39.    To show the active users stats (x Members, X Guests, etc)
  40.    
  41.    include("http://domain.com/forums/ssi.php?a=active");
  42.    
  43. */
  44.  
  45. //-----------------------------------------------
  46. // USER CONFIGURABLE ELEMENTS
  47. //-----------------------------------------------
  48.  
  49. // Root path
  50.  
  51. $root_path = "./";
  52.  
  53. $templates_dir = "./ssi_templates";
  54.  
  55.  
  56. //-----------------------------------------------
  57. // NO USER EDITABLE SECTIONS BELOW
  58. //-----------------------------------------------
  59.  
  60. error_reporting  (E_ERROR | E_WARNING | E_PARSE);
  61. set_magic_quotes_runtime(0);
  62.  
  63. class info {
  64.  
  65.     var $input      = array();
  66.     var $base_url   = "";
  67.     var $vars       = "";
  68.     function info() {
  69.         global $sess, $std, $DB, $root_path, $INFO;
  70.         
  71.         $this->vars = &$INFO;
  72.         
  73.     }
  74. }
  75.  
  76. //--------------------------------
  77. // Import $INFO, now!
  78. //--------------------------------
  79.  
  80. require $root_path."conf_global.php";
  81.  
  82. //--------------------------------
  83. // Require our global functions
  84. //--------------------------------
  85.  
  86. require $root_path."sources/functions.php";
  87.  
  88. $std   = new FUNC;
  89.  
  90. //--------------------------------
  91. // Load the DB driver and such
  92. //--------------------------------
  93.  
  94. $INFO['sql_driver'] = !$INFO['sql_driver'] ? 'mySQL' : $INFO['sql_driver'];
  95.  
  96. $to_require = $root_path."sources/Drivers/".$INFO['sql_driver'].".php";
  97. require ($to_require);
  98.  
  99. $DB = new db_driver;
  100.  
  101. $DB->obj['sql_database']     = $INFO['sql_database'];
  102. $DB->obj['sql_user']         = $INFO['sql_user'];
  103. $DB->obj['sql_pass']         = $INFO['sql_pass'];
  104. $DB->obj['sql_host']         = $INFO['sql_host'];
  105. $DB->obj['sql_tbl_prefix']   = $INFO['sql_tbl_prefix'];
  106.  
  107. // Get a DB connection
  108.  
  109. $DB->connect();
  110.  
  111. //--------------------------------
  112. // Wrap it all up in a nice easy to
  113. // transport super class
  114. //--------------------------------
  115.  
  116. $ibforums             = new info();
  117.  
  118. //--------------------------------
  119. //  Set up our vars
  120. //--------------------------------
  121.  
  122. $ibforums->input      = $std->parse_incoming();
  123. $ibforums->base_url   = $ibforums->vars['board_url'].'/index.'.$ibforums->vars['php_ext'];
  124.  
  125. //--------------------------------
  126. // What to do?
  127. //--------------------------------
  128.  
  129. switch ($ibforums->input['a'])
  130. {
  131.     case 'news':
  132.         do_news();
  133.         break;
  134.         
  135.     case 'active':
  136.         do_active();
  137.         break;
  138.         
  139.     case 'stats':
  140.         do_stats();
  141.         break;
  142.         
  143.     default:
  144.         echo("An error occured whilst processing this directive");
  145.         exit();
  146.         break;
  147. }
  148.  
  149. //+-------------------------------------------------
  150. // Import the stats! WOOHOO
  151. //+-------------------------------------------------
  152.  
  153. function do_stats()
  154. {
  155.     global $DB, $ibforums, $root_path, $templates_dir, $std;
  156.     
  157.     // Load the template...
  158.     
  159.     $template = load_template("stats.html");
  160.     
  161.     $to_echo = "";
  162.     
  163.     // Get the topics, member info and other stuff
  164.     $time = time() - 900;
  165.             
  166.     $DB->query("SELECT * FROM ibf_stats");
  167.     $stats = $DB->fetch_row();
  168.     
  169.     $total_posts = $stats['TOTAL_REPLIES']+$stats['TOTAL_TOPICS'];
  170.     
  171.     $to_echo  = parse_template( $template,
  172.                                 array (
  173.                                          'total_posts'  => $total_posts,
  174.                                          'topics'       => $stats['TOTAL_TOPICS'],
  175.                                          'replies'      => $stats['TOTAL_REPLIES'],
  176.                                          'members'      => $stats['MEM_COUNT']
  177.                                       )
  178.                                 );
  179.     
  180.     
  181.     echo $to_echo;
  182.     
  183.     exit();
  184.     
  185. }
  186.  
  187.  
  188. function do_news()
  189. {
  190.     global $DB, $ibforums, $root_path, $templates_dir, $std;
  191.     
  192.     if ( (! $ibforums->vars['news_forum_id']) or ($ibforums->vars['news_forum_id'] == "" ) )
  193.     {
  194.         fatal_error("No news forum assigned");
  195.     }
  196.     
  197.     $perpage = $ibforums->input['show'] ? $ibforums->input['show'] : 10;
  198.     
  199.     // Load the template...
  200.     
  201.     $template = load_template("news.html");
  202.     
  203.     $to_echo = "";
  204.     
  205.     // Get the topics, member info and other stuff
  206.     
  207.     $DB->query("SELECT m.name as member_name, m.id as member_id, m.title as member_title, m.avatar, m.avatar_size, m.posts, t.*, p.* FROM ibf_members m, ibf_posts p, ibf_topics t ".
  208.                "WHERE t.forum_id = '".$ibforums->vars['news_forum_id']."' AND p.topic_id=t.tid AND p.new_topic=1 AND m.id=t.starter_id ".
  209.                "ORDER BY t.tid DESC LIMIT 0, $perpage");
  210.                
  211.     if ( ! $DB->get_num_rows() )
  212.     {
  213.         fatal_error("Could not get the information from the database");
  214.     }
  215.  
  216.     while ( $row = $DB->fetch_row() )
  217.     {
  218.         $to_echo .= parse_template( $template,
  219.                                     array (
  220.                                              'profile_link'   => $ibforums->base_url."?act=Profile&CODE=03&MID=".$row['member_id'],
  221.                                              'member_name'    => $row['member_name'],
  222.                                              'post_date'      => $std->get_date( $row['start_date'], 'LONG' ),
  223.                                              'topic_title'    => $row['title'],
  224.                                              'post'           => $row['post'],
  225.                                              'comments'       => $row['posts'],
  226.                                              'view_all_link'  => $ibforums->base_url."?act=ST&f={$row['forum_id']}&t={$row['tid']}"
  227.                                           )
  228.                                     );
  229.     }
  230.     
  231.     echo $to_echo;
  232.     
  233.     exit();
  234.     
  235. }
  236.  
  237.  
  238. function do_active()
  239. {
  240.     global $DB, $ibforums, $root_path, $templates_dir, $std;
  241.     
  242.     // Load the template...
  243.     
  244.     $template = load_template("active.html");
  245.     
  246.     $to_echo = "";
  247.     
  248.     // Get the topics, member info and other stuff
  249.     $time = time() - 900;
  250.             
  251.     $DB->query("SELECT s.member_id, s.member_name, s.login_type, g.suffix, g.prefix FROM ibf_sessions s, ibf_groups g WHERE running_time > '$time' AND g.g_id=s.member_group ORDER BY running_time DESC");
  252.     
  253.     // cache all printed members so we don't double print them
  254.     $cached = array();
  255.     
  256.     $active = array();
  257.     
  258.     while ($result = $DB->fetch_row() )
  259.     {
  260.         if ($result['member_id'] == 0)
  261.         {
  262.             $active['GUESTS']++;
  263.         }
  264.         else
  265.         {
  266.             if (empty( $cached[ $result['member_id'] ] ) )
  267.             {
  268.                 $cached[ $result['member_id'] ] = 1;
  269.                 if ($result['login_type'] == 1)
  270.                 {
  271.                     $active['ANON']++;
  272.                 }
  273.                 else
  274.                 {
  275.                     $active['MEMBERS']++;
  276.                 }
  277.             }
  278.             
  279.         }
  280.     }
  281.     
  282.     $active['TOTAL'] = $active['MEMBERS'] + $active['GUESTS'] + $active['ANON'];
  283.                
  284.     
  285.     $to_echo  = parse_template( $template,
  286.                                 array (
  287.                                          'total'   => $active['TOTAL']   ? $active['TOTAL']   : 0 ,
  288.                                          'members' => $active['MEMBERS'] ? $active['MEMBERS'] : 0,
  289.                                          'guests'  => $active['GUESTS']  ? $active['GUESTS']  : 0,
  290.                                          'anon'    => $active['ANON']    ? $active['ANON']    : 0,
  291.                                       )
  292.                                 );
  293.     
  294.     
  295.     echo $to_echo;
  296.     
  297.     exit();
  298.     
  299. }
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306. //+-------------------------------------------------
  307. // GLOBAL ROUTINES
  308. //+-------------------------------------------------
  309.  
  310.  
  311. function parse_template( $template, $assigned=array() )
  312. {
  313.     
  314.     foreach( $assigned as $word => $replace)
  315.     {
  316.         $template = preg_replace( "/\{$word\}/i", "$replace", $template );
  317.     }
  318.     
  319.     return $template;
  320. }
  321.  
  322.  
  323.  
  324. function load_template($template="")
  325. {
  326.     global $templates_dir;
  327.     
  328.     $filename = $templates_dir."/".$template;
  329.     
  330.     if ( file_exists($filename) )
  331.     {
  332.         if ( $FH = fopen($filename, 'r') )
  333.         {
  334.             $template = fread( $FH, filesize($filename) );
  335.             fclose($FH);
  336.         }
  337.         else
  338.         {
  339.             fatal_error("Couldn't open the template file");
  340.         }
  341.     }
  342.     else
  343.     {
  344.         fatal_error("Template file does not exist");
  345.     }
  346.     
  347.     return $template;
  348.  
  349. }
  350.  
  351. function fatal_error($message="") {
  352.     echo("An error occured whilst processing this directive");
  353.     if ($message)
  354.     {
  355.         echo("<br>$message");
  356.     }
  357.     exit();
  358. }
  359. ?>
  360.